#@dir=('BRCA','BLCA','COAD','KIRC','LAML','LGG','LUAD','PRAD','READ','LUSC','OV','GBM');
#@dir=('emerge','pancreas','vte');
@dir=('cases');
$maindir="/data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/TCGA/GBM";
for($i=0;$i<@dir;$i++)
{
	print "processing $dir[$i]\n";
	$dir=$dir[$i];
	open(WRBUFF,">$maindir/$dir/runsh_it_$dir") or die " no file exists runshapeit\n";
	print WRBUFF '#! /bin/bash'."\n";
	print WRBUFF '#$ -q 1-day'."\n";
	print WRBUFF '#$ -l h_vmem=10G'."\n";
	print WRBUFF '#$ -M naresh.prodduturi@mayo.edu'."\n";
	print WRBUFF '#$ -m a'."\n";
	print WRBUFF '#$ -V'."\n";
	print WRBUFF '#$ -cwd'."\n";
	$sys="perl /data4/bsi/RandD/Workflow/genotyping_QC_FWD/perl_script_filter_data_based_on_1kg_ref.pl  $maindir/$dir/chr8q24_$dir.tped $maindir/$dir/maf_lt_015_chr8q24_$dir.tped";
	print WRBUFF $sys."\n";
	$sys="cp $maindir/$dir/chr8q24_$dir.tfam $maindir/$dir/maf_lt_015_chr8q24_$dir.tfam";
	#print WRBUFF $sys."\n";
	system($sys);
	$sys="/data4/bsi/RandD/Workflow/genotyping_QC_FWD/bin/plink/plink --tfile $maindir/$dir/maf_lt_015_chr8q24_$dir  --make-bed --out $maindir/$dir/maf_lt_015_chr8q24_$dir";
	print WRBUFF $sys."\n";
	$sys="/data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/shapeit  --input-bed  $maindir/$dir/maf_lt_015_chr8q24_$dir.bed $maindir/$dir/maf_lt_015_chr8q24_$dir.bim $maindir/$dir/maf_lt_015_chr8q24_$dir.fam --input-map /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/genetic_map_chr8_combined_b37.txt  --output-max  $maindir/$dir/maf_lt_015_chr8q24_$dir.haps $maindir/$dir/maf_lt_015_chr8q24_$dir.sample  --seed 123456789 --states-phase 100";
	print WRBUFF $sys."\n";
	$sys="gzip $maindir/$dir/maf_lt_015_chr8q24_$dir.haps";
	print WRBUFF $sys."\n";
	$sys="/data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/impute_v2.2.2_x86_64_static/impute2 -use_prephased_g -allow_large_regions -m /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/genetic_map_chr8_combined_b37.txt -h /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.hap.gz -l /data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr8_impute.legend.gz -int 126000000 133000000 -known_haps_g $maindir/$dir/maf_lt_015_chr8q24_$dir.haps.gz -o $maindir/$dir/impute_8q24_out";
	print WRBUFF $sys."\n";
	$numsamp=`wc -l  $maindir/$dir/maf_lt_015_chr8q24_$dir.tfam`;
	$numsamp=~ s/ .+//g;
	print $numsamp."\n";
	$sys= "perl /data4/bsi/bioinf_ext1/s112349.ucsf/new_request_aug_20_2012/kk.pl $maindir/$dir/beagle1.gz $numsamp";
	system($sys);
	#print WRBUFF $sys."\n";
	$sys = "cut -f2,4- -d ' ' $maindir/$dir/impute_8q24_out|gzip > $maindir/$dir/beagle2.gz";
	print WRBUFF $sys."\n";
	$sys ="zcat $maindir/$dir/beagle1.gz $maindir/$dir/beagle2.gz |/usr/java/latest/bin/java  -Xmx3000m -jar /data4/bsi/RandD/Workflow/genotyping_1000genome_impute/bin/gprobsmetrics.jar |gzip > $maindir/$dir/beagle.r2.gz";
	print WRBUFF $sys."\n";	
	#system("qsub $maindir/$dir/runsh_it_$dir");
}
